import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;


public class Score{
	static int score = 0;

	private int max = 0;

	public void addScore(){
		score += 1000;

		max = fileReader();

		if(max < score){
			max = score;
		}

		fileWriter(max);
	}

/*
 * スコア初期化
 */
	public static void scoreInit(){
		score = 0;
	}

/*
 * ハイスコア初期化（仮）
 */
	public void maxInit(){
		fileWriter(5000);
	}

/*
 * ファイル読み込み
 */
	public int fileReader(){
		String st = "No Data...";
		try{
			File file = new File("src/score.txt");
			FileReader filereader = new FileReader(file);
			BufferedReader bufreader = new BufferedReader(filereader);
			st = bufreader.readLine();
			bufreader.close();
		}catch(FileNotFoundException e){
			System.out.println(e);
		}catch(IOException e){
			System.out.println(e);
		}

		try{
			return Integer.parseInt(st);
		}catch(NumberFormatException e){
			return -1;
		}
	}

/*
 * ファイル書き込み
 */
	public void fileWriter(int max){
		try {
			File file2 = new File("src/score.txt");
			FileWriter filewriter = new FileWriter(file2);
			BufferedWriter bufwriter = new BufferedWriter(filewriter);
			PrintWriter priwriter = new PrintWriter(bufwriter);
			priwriter.println(max);
			priwriter.close();
		}catch(FileNotFoundException e){
			System.out.println(e);
		}catch(IOException e){
			System.out.println(e);
		}
	}
}